package com.example.expandablelistview.animation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import com.example.expandablelistview.R;

public class AnimationEx extends Activity {
	ImageView mAnimTarget;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.animationex);
		mAnimTarget = (ImageView) findViewById(R.id.animtarget);

		findViewById(R.id.btntrans1).setOnClickListener(translistener);
		findViewById(R.id.btntrans2).setOnClickListener(translistener);
		findViewById(R.id.btntrans3).setOnClickListener(translistener);

		findViewById(R.id.btnrotate1).setOnClickListener(rotatelistener);
		findViewById(R.id.btnrotate2).setOnClickListener(rotatelistener);
		findViewById(R.id.btnrotate3).setOnClickListener(rotatelistener);

		findViewById(R.id.btnscale1).setOnClickListener(scalelistener);
		findViewById(R.id.btnscale2).setOnClickListener(scalelistener);
		findViewById(R.id.btnscale3).setOnClickListener(scalelistener);

		findViewById(R.id.btnalpha1).setOnClickListener(alphalistener);
		findViewById(R.id.btnalpha2).setOnClickListener(alphalistener);
	} // end of onCreate

	View.OnClickListener rotatelistener = new View.OnClickListener() {
		Animation anim = null;

		public void onClick(View v) {
			switch (v.getId()) {
				case R.id.btnrotate1:
					anim = new RotateAnimation(0, -180);
					break;
				case R.id.btnrotate2:
					anim = new RotateAnimation(0, -180,
							Animation.RELATIVE_TO_SELF, 0.5f,
							Animation.RELATIVE_TO_SELF, 0.5f);
					break;
				case R.id.btnrotate3:
					anim = new RotateAnimation(0, 90,
							Animation.RELATIVE_TO_PARENT, 0.5f,
							Animation.RELATIVE_TO_PARENT, 1.0f);
					break;
			}
			anim.setDuration(1000);
			mAnimTarget.startAnimation(anim);
		}
	}; // end of rotatelistener

	View.OnClickListener scalelistener = new View.OnClickListener() {
		Animation anim = null;

		public void onClick(View v) {
			switch (v.getId()) {
				case R.id.btnscale1:
					anim = new ScaleAnimation(0, 1, 0, 1);
					break;
				case R.id.btnscale2:
					anim = new ScaleAnimation(0, 1, 0, 1,
							Animation.RELATIVE_TO_SELF, 0.5f,
							Animation.RELATIVE_TO_SELF, 0.5f);
					break;
				case R.id.btnscale3:
					anim = new ScaleAnimation(1, 0, 1, 0,
							Animation.RELATIVE_TO_SELF, 0.5f,
							Animation.RELATIVE_TO_SELF, 0.5f);
					break;
			}
			anim.setDuration(1000);
			mAnimTarget.startAnimation(anim);
		}
	}; // end of scalelistener
	
	View.OnClickListener alphalistener = new View.OnClickListener() {
		Animation anim = null;

		public void onClick(View v) {
			switch (v.getId()) {
				case R.id.btnalpha1:
					anim = new AlphaAnimation(0, 1);
					break;
				case R.id.btnalpha2:
					anim = new AlphaAnimation(1, 0);
					break;
			}
			anim.setDuration(1000);
			mAnimTarget.startAnimation(anim);
		}
	}; // end of alphalistener
	
	View.OnClickListener translistener = new View.OnClickListener() {
		Animation anim = null;

		public void onClick(View v) {
			switch (v.getId()) {
				case R.id.btntrans1:
					anim = new TranslateAnimation(0, 200, 0, 0);
					break;
				case R.id.btntrans2:
					anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
							0, Animation.RELATIVE_TO_SELF, 1,
							Animation.RELATIVE_TO_PARENT, 0,
							Animation.RELATIVE_TO_PARENT, 0);
					break;
				case R.id.btntrans3:
					anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,
							0, Animation.RELATIVE_TO_PARENT, 1,
							Animation.RELATIVE_TO_PARENT, 0,
							Animation.RELATIVE_TO_PARENT, 0);
					break;
			}
			anim.setDuration(1000);
			mAnimTarget.startAnimation(anim);
		}
	}; // end of translistner
}// end of TweenAni

